const eventNames: string[] = ["INPUT:SUBMIT", "ANALYZE:RESULT"];

type EventNames = (typeof eventNames)[number];

class EventBus {
    private listeners: Record<EventNames, Set<Function>> = {
        "INPUT:SUBMIT": new Set(),
        "ANALYZE:RESULT": new Set(),
    };

    on(eventName: EventNames, listener: Function) {
        this.listeners[eventName].add(listener);
    }

    emit(eventName: EventNames, ...args: any[]) {
        this.listeners[eventName].forEach((listener) => listener(...args));
    }
}

const eventBus = new EventBus();

export default eventBus;
